package a_Web.src.main.java.com.example.demo;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/home")
public class home extends HttpServlet {
    private String message;
    public void init() throws ServletException
    {
        // 执行必需的初始化
        message = "Hello World";
    }
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws ServletException, IOException
    {
        // 设置响应内容类型
        response.setContentType("text/html");
        // 实际的逻辑是在这里
        PrintWriter out = response.getWriter();
        out.println("<h1> Get：" + message + "</h1>");
        System.out.println("home:get");
    }
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
            throws ServletException, IOException
    {
        // 设置响应内容类型
        response.setContentType("text/html");
        // 实际的逻辑是在这里
        PrintWriter out = response.getWriter();
        out.println("<h1> post:" + message + "</h1>");
        System.out.println("home:post");
    }


    public void destroy()
    {
        // 什么也不做
        System.out.println("页面注销， 关闭数据库链接，清楚缓存");
    }

}
